package com.dhecp.project.hr.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.project.common.service.UpdateLogService;
import com.dhecp.project.common.service.impl.BaseModuleServiceImpl;
import com.dhecp.project.hr.domain.AmazonShopOrder;
import com.dhecp.project.hr.mapper.AmazonShopOrderMapper;
import com.dhecp.project.hr.service.AmazonShopOrderService;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * @program: kjecp
 * @description: 店铺订单
 * @author: hlf
 * @create: 2022-10-09 14:36
 */
@Service
public class AmazonShopOrderServiceImpl extends BaseModuleServiceImpl implements AmazonShopOrderService {

    @Autowired
    private AmazonShopOrderMapper businessMapper;

    @Autowired
    private UpdateLogService updateLogService;
    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;


    /**
     * 查询
     * @param params
     * @return List - AttendanceQJ
     * @throws Exception
     * @author DH-Xxj
     */
    @Override
    public List<AmazonShopOrder> queryList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        if (params.get("checkwsx") != null && params.get("checkwsx").equals("1")){
            params.put("isTwoDay",1);
            params.remove("checkwsx");
        }
        if (params.get("checkwsx1") != null && params.get("checkwsx1").equals("1")){
            params.put("isClose",1);
            params.remove("checkwsx1");
        }
        if (params.get("checkwsx2") != null && params.get("checkwsx2").equals("1")){
            params.put("isDiscard",1);
            params.remove("checkwsx2");
        }
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
//        String otherWhereStr = "";
//        if ((params.get("otherWhere") == null || params.get("otherWhere") == "") && ShiroUtils.getMandatorLevel() < 6){
//            otherWhereStr = "c1.CUser = '" + ShiroUtils.getMandatorId() + "'";
//        }
//
//        if (!"".equals(otherWhereStr)){
//            params.put("otherWhereStr", otherWhereStr);
//        }

        if (params.get("field") == null || params.get("field") == ""){
            String orderBy = "t1.purchaseDate desc";
            PageUtils.startPageOrder(orderBy);
        }else{
            PageUtils.startPage();
        }
        return businessMapper.select(params);
    }

    /**
     * @Description: 查询指定单nid的首记录
     * @Param: [params]
     * @return: com.dhecp.project.storage.domain.AmazonShopOrder
     * @Author: hlf
     * @date: 2022-05-09 10:10
     */
    @Override
    public AmazonShopOrder findByGuid(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        return businessMapper.findById(params);
    }

    /**
     * 删除
     * @param params
     * @return AjaxResult
     * @author DH-Xxj
     */
    @Override
    public AjaxResult deleteData(Map<String, Object> params) {
        List<AmazonShopOrder> businessDataList = JSON.parseArray(params.get("infoItems").toString(), AmazonShopOrder.class);
        if (businessDataList == null || businessDataList.size() == 0) {
            return AjaxResult.error(MessageUtils.message("module.error.jsontoentyerror"));
        }
        for (AmazonShopOrder businessData : businessDataList) {
            businessMapper.delete(businessData);
        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
    }
}